package com.yami.shop.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.ImMsgBizSkills;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.ImMsgBizSkillsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * 客服自动回复表
 *
 * @author LGH
 * @date 2023-03-07 17:16:11
 */
@RestController
@RequestMapping("/platform/imMsgBizSkills")
@Tag(name = "客服自动回复表")
public class ImMsgBizSkillsController {

    @Autowired
    private ImMsgBizSkillsService imMsgBizSkillsService;

    @GetMapping("/page")
    @Operation(summary = "获取客服自动回复表列表", description = "分页获取客服自动回复表列表")
    @Parameters({
            @Parameter(name = "keywords", description = "关键字" ),
            @Parameter(name = "content", description = "内容" ),
    })
    public ServerResponseEntity<IPage<ImMsgBizSkills>> getImMsgBizSkillsPage(PageParam<ImMsgBizSkills> page,  @RequestParam(value = "keywords", required = false) String keywords,
                                                                             @RequestParam(value = "content", required = false) String content) {
        Long shopId = Constant.PLATFORM_SHOP_ID;
        return ServerResponseEntity.success(imMsgBizSkillsService.page(page, shopId, keywords, content));
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "获取客服自动回复表", description = "根据id获取客服自动回复表")
    @Parameter(name = "id", description = "客服自动回复表", required = true)
    public ServerResponseEntity<ImMsgBizSkills> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(imMsgBizSkillsService.getById(id));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform:imMsgBizSkills:save')")
    @Operation(summary = "保存客服自动回复表", description = "保存客服自动回复表")
    public ServerResponseEntity<Boolean> save(@RequestBody @ParameterObject ImMsgBizSkills imMsgBizSkills) {
        imMsgBizSkills.setShopId(Constant.PLATFORM_SHOP_ID);
        return ServerResponseEntity.success(imMsgBizSkillsService.insert(imMsgBizSkills));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform:imMsgBizSkills:update')")
    @Operation(summary = "更新客服自动回复表", description = "更新客服自动回复表")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @ParameterObject ImMsgBizSkills imMsgBizSkills) {
        return ServerResponseEntity.success(imMsgBizSkillsService.update(imMsgBizSkills));
    }

    @DeleteMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('platform:imMsgBizSkills:delete')")
    @Operation(summary = "删除客服自动回复表", description = "根据客服自动回复表id删除客服自动回复表")
    @Parameter(name = "id", description = "客服自动回复表", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
        return ServerResponseEntity.success(imMsgBizSkillsService.deleteById(id));
    }
}
